<template>
  <div class="swiper banner" id="banner">
    <div class="swiper-wrapper">
      <div
        class="swiper-slide"
        :class="[showIndex == index ? 'active' : '']"
        v-for="(item, index) in dataList"
        :key="index"
        @mouseenter="mouseenterFun(index)"
      >
        <img
          @click="openLink('studentStyleDetails', item, index)"
          class="banner-img"
          :src="item.imageUrl"
          v-imgError
          alt=""
        />
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/css/swiper.min.css";
export default {
  // 组件名称
  name: "demo",
  // 组件参数 接收来自父组件的数据
  props: {
    dataList: Array,
    total: Number,
  },
  // 局部注册的组件
  components: {},
  // 组件状态值
  data() {
    return {
      swiper: null,
      currentRow: null,
      studentList: [],
      showIndex: 0,
    };
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 组件方法
  methods: {
    initSwiper() {
      if (this.swiper === null) {
        let swiper = new Swiper("#banner", {
          slidesPerView: "auto",
          // spaceBetween: 30,
        });
      }
    },
    openLink(str, row, index) {
      this.currentRow = row;
      this.$router.push({
        name: str,
        query: { id: row.id, index, total: this.total },
      });
    },
    mouseenterFun(index) {
      if (this.showIndex == index) return;
      this.showIndex = index;
      this.$parent.changeIndex(index);
    },
  },
  /**
   * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
   */
  created() {},
  /**
   * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
   * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
   */
  mounted() {},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.banner {
  position: relative;
  width: calc(100% + 50px);
  padding: 50px 50px;
  left: -50px;
}
.swiper {
  overflow: hidden;
}
.swiper-slide {
  text-align: left;
  font-size: 18px;
  background: #fff;
  width: 212px !important;
  height: 212px;
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
  border-radius: 12px;
  margin-right: 35px;
}
.swiper-slide:hover,
.active {
  transform: scale(1.1, 1.1);
  border: 6px solid rgba(47, 142, 254, 1);
}

.banner-img {
  position: absolute;
  left: -1px;
  top: -1px;
  width: 202px;
  height: 202px;
  transition: all 0.3s;
  background: linear-gradient(198deg, #d7d7d7 0%, #ececec 62%, #c8c8ca 100%);
  box-shadow: 0px 3px 15px 0px rgba(0, 0, 0, 0.12);
  border-radius: 8px;
}
</style>
